package org.htmlparser.beans;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Vector;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.ListModel;

public class BeanyBaby extends JFrame
  implements PropertyChangeListener, ActionListener, MouseListener
{
  private JMenuItem mBack;
  private JCheckBoxMenuItem mCollapse;
  protected int mCrumb;
  private JMenuItem mForward;
  private HTMLLinkBean mLinkBean;
  private JCheckBoxMenuItem mLinks;
  private JCheckBoxMenuItem mNobreak;
  private JSplitPane mSplitPane;
  private HTMLTextBean mStringBean;
  private JTextField mTextField;
  protected Vector mTrail;

  public BeanyBaby()
  {
    initComponents();
    this.mTrail = new Vector();
    this.mCrumb = -1;
    setVisible(true);
    this.mSplitPane.setDividerLocation(0.5D);
    setVisible(false);
    this.mLinkBean.addPropertyChangeListener(this);
    this.mStringBean.addPropertyChangeListener(this);
    this.mTextField.addActionListener(this);
    this.mLinkBean.addMouseListener(this);
    this.mLinks.setSelected(this.mStringBean.getLinks());
    this.mCollapse.setSelected(this.mStringBean.getCollapse());
    this.mNobreak.setSelected(this.mStringBean.getReplaceNonBreakingSpaces());
  }

  static void access$000(BeanyBaby paramBeanyBaby, WindowEvent paramWindowEvent)
  {
    paramBeanyBaby.exitForm(paramWindowEvent);
  }

  private void exitForm(WindowEvent paramWindowEvent)
  {
    System.exit(0);
  }

  private void initComponents()
  {
    JMenuBar localJMenuBar = new JMenuBar();
    setJMenuBar(localJMenuBar);
    JMenu localJMenu1 = new JMenu();
    this.mBack = new JMenuItem();
    this.mForward = new JMenuItem();
    JMenu localJMenu2 = new JMenu();
    this.mLinks = new JCheckBoxMenuItem();
    this.mCollapse = new JCheckBoxMenuItem();
    this.mNobreak = new JCheckBoxMenuItem();
    JPanel localJPanel = new JPanel();
    this.mSplitPane = new JSplitPane();
    JScrollPane localJScrollPane1 = new JScrollPane();
    this.mLinkBean = new HTMLLinkBean();
    JScrollPane localJScrollPane2 = new JScrollPane();
    this.mStringBean = new HTMLTextBean();
    this.mTextField = new JTextField();
    localJMenu1.setMnemonic('G');
    localJMenu1.setText("Go");
    localJMenu1.setToolTipText("crude URL navigation");
    this.mBack.setMnemonic('B');
    this.mBack.setText("Back");
    this.mBack.setToolTipText("back one URL");
    this.mBack.setName("Back");
    this.mBack.addActionListener(this);
    localJMenu1.add(this.mBack);
    this.mForward.setMnemonic('F');
    this.mForward.setText("Forward");
    this.mForward.setToolTipText("forward one URL");
    this.mForward.setName("Forward");
    this.mForward.addActionListener(this);
    localJMenu1.add(this.mForward);
    localJMenuBar.add(localJMenu1);
    localJMenu2.setMnemonic('O');
    localJMenu2.setText("Options");
    localJMenu2.setToolTipText("Bean settings");
    this.mLinks.setMnemonic('L');
    this.mLinks.setText("Links");
    this.mLinks.setToolTipText("show/hide links in text");
    this.mLinks.setName("Links");
    this.mLinks.addActionListener(this);
    localJMenu2.add(this.mLinks);
    this.mCollapse.setMnemonic('C');
    this.mCollapse.setText("Collapse");
    this.mCollapse.setToolTipText("collapse/retain whitespace sequences");
    this.mCollapse.setName("Collapse");
    this.mCollapse.addActionListener(this);
    localJMenu2.add(this.mCollapse);
    this.mNobreak.setMnemonic('N');
    this.mNobreak.setText("Non-breaking Spaces");
    this.mNobreak.setToolTipText("replace/retain non-breaking spaces");
    this.mNobreak.setName("Nobreak");
    this.mNobreak.addActionListener(this);
    localJMenu2.add(this.mNobreak);
    localJMenuBar.add(localJMenu2);
    setTitle("BeanyBaby");
    addWindowListener(new 1(this));
    localJPanel.setLayout(new BorderLayout());
    localJScrollPane1.setViewportView(this.mLinkBean);
    this.mSplitPane.setLeftComponent(localJScrollPane1);
    localJScrollPane2.setViewportView(this.mStringBean);
    this.mSplitPane.setRightComponent(localJScrollPane2);
    localJPanel.add(this.mSplitPane, "Center");
    this.mTextField.setToolTipText("Enter the URL to view");
    localJPanel.add(this.mTextField, "South");
    getContentPane().add(localJPanel, "Center");
    pack();
    Dimension localDimension = Toolkit.getDefaultToolkit().getScreenSize();
    setSize(new Dimension(640, 480));
    setLocation((localDimension.width - 640) / 2, (localDimension.height - 480) / 2);
  }

  public static void main(String[] paramArrayOfString)
  {
    BeanyBaby localBeanyBaby = new BeanyBaby();
    localBeanyBaby.setVisible(true);
    if (paramArrayOfString.length <= 0)
      localBeanyBaby.setURL("http://www.slashdot.org");
    while (true)
    {
      return;
      localBeanyBaby.setURL(paramArrayOfString[0]);
    }
  }

  public void actionPerformed(ActionEvent paramActionEvent)
  {
    Object localObject = paramActionEvent.getSource();
    if (localObject == this.mTextField)
    {
      String str5 = this.mTextField.getText();
      this.mTextField.selectAll();
      setURL(str5);
    }
    while (true)
    {
      label131: String str1;
      label207: 
      do
        while (true)
        {
          do
          {
            do
              while (true)
              {
                JMenuItem localJMenuItem;
                String str4;
                do
                  while (true)
                  {
                    while (true)
                    {
                      return;
                      if (!(localObject instanceof JCheckBoxMenuItem))
                        break label131;
                      localJMenuItem = (JMenuItem)localObject;
                      str4 = localJMenuItem.getName();
                      if (!("Links".equals(str4)))
                        break;
                      this.mStringBean.setLinks(localJMenuItem.isSelected());
                    }
                    if (!("Collapse".equals(str4)))
                      break;
                    this.mStringBean.setCollapse(localJMenuItem.isSelected());
                  }
                while (!("Nobreak".equals(str4)));
                this.mStringBean.setReplaceNonBreakingSpaces(localJMenuItem.isSelected());
              }
            while (!(localObject instanceof JMenuItem));
            str1 = ((JMenuItem)localObject).getName();
            if (!("Back".equals(str1)))
              break label207;
          }
          while (this.mCrumb <= 0);
          this.mCrumb -= 1;
          String str3 = (String)this.mTrail.elementAt(this.mCrumb);
          this.mCrumb -= 1;
          setURL(str3);
        }
      while ((!("Forward".equals(str1))) || (this.mCrumb >= this.mTrail.size()));
      this.mCrumb = (1 + this.mCrumb);
      String str2 = (String)this.mTrail.elementAt(this.mCrumb);
      this.mCrumb -= 1;
      setURL(str2);
    }
  }

  public void mouseClicked(MouseEvent paramMouseEvent)
  {
    if (2 == paramMouseEvent.getClickCount())
    {
      int i = this.mLinkBean.locationToIndex(paramMouseEvent.getPoint());
      setURL(this.mLinkBean.getModel().getElementAt(i).toString());
    }
  }

  public void mouseEntered(MouseEvent paramMouseEvent)
  {
  }

  public void mouseExited(MouseEvent paramMouseEvent)
  {
  }

  public void mousePressed(MouseEvent paramMouseEvent)
  {
  }

  public void mouseReleased(MouseEvent paramMouseEvent)
  {
  }

  public void propertyChange(PropertyChangeEvent paramPropertyChangeEvent)
  {
    Object localObject = paramPropertyChangeEvent.getSource();
    if (localObject == this.mLinkBean)
      if (!(this.mLinkBean.getURL().equals(this.mStringBean.getURL())))
        this.mStringBean.setURL(this.mLinkBean.getURL());
    while (true)
    {
      String str;
      do
        while (true)
        {
          while (true)
          {
            do
              return;
            while (localObject != this.mStringBean);
            if (!(this.mStringBean.getURL().equals(this.mLinkBean.getURL())))
              this.mLinkBean.setURL(this.mStringBean.getURL());
            str = paramPropertyChangeEvent.getPropertyName();
            if (!(str.equals("links")))
              break;
            this.mLinks.setSelected(((Boolean)paramPropertyChangeEvent.getNewValue()).booleanValue());
          }
          if (!(str.equals("collapse")))
            break;
          this.mCollapse.setSelected(((Boolean)paramPropertyChangeEvent.getNewValue()).booleanValue());
        }
      while (!(str.equals("replaceNonBreakingSpaces")));
      this.mNobreak.setSelected(((Boolean)paramPropertyChangeEvent.getNewValue()).booleanValue());
    }
  }

  public void setURL(String paramString)
  {
    boolean bool1;
    JMenuItem localJMenuItem2;
    boolean bool2;
    this.mTextField.setText(paramString);
    this.mCrumb = (1 + this.mCrumb);
    if (this.mTrail.size() <= this.mCrumb)
    {
      this.mTrail.addElement(paramString);
      this.mLinkBean.setURL(paramString);
      JMenuItem localJMenuItem1 = this.mBack;
      if (this.mCrumb <= 0)
        break label115;
      bool1 = true;
      localJMenuItem1.setEnabled(bool1);
      localJMenuItem2 = this.mForward;
      if (1 + this.mCrumb >= this.mTrail.size())
        break label120;
      bool2 = true;
    }
    while (true)
    {
      while (true)
      {
        while (true)
        {
          localJMenuItem2.setEnabled(bool2);
          return;
          this.mTrail.setElementAt(paramString, this.mCrumb);
        }
        label115: bool1 = false;
      }
      label120: bool2 = false;
    }
  }
}